package com.zkingsoft.services.distribution.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zkingsoft.dao.distribution.DisDesignerDao;
import com.zkingsoft.exception.GlobleException;
import com.zkingsoft.model.distribution.DisDesigner;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.services.distribution.DisDesignerService;
import com.zkingsoft.sqlUtil.ServiceUtil;
import com.zkingsoft.util.ModelUtils;

/**
 * This field was generated by Zking.software.Codegen.
 * 
 * @date 2017-06-26 07:15
 */
@Service("disDesignerService")
public class DisDesignerServiceImpl implements DisDesignerService {

	@Autowired
	private DisDesignerDao disDesignerDao;

	@Autowired
	private ServiceUtil serviceUtil;
	
	@Override
	public int add(DisDesigner disDesigner) {
		if (serviceUtil.addCheckRepeat("dis_designer", "des_account", disDesigner.getDesAccount())) {
			throw new GlobleException("手机号已经被占用");
		}
		return disDesignerDao.insert(disDesigner);

	}

	@Override
	public int batchAdd(List<DisDesigner> disDesignerList) {
		int num = 0;

		int c = 10000;
		int size = disDesignerList.size() / c + 1;
		for (int i = 0; i < size; i++) {
			int begin = i * c;
			int end = (i + 1) * c;
			end = end >= disDesignerList.size() ? disDesignerList.size() : end;
			List<DisDesigner> insertList = disDesignerList.subList(begin, end);
			num += disDesignerDao.batchInsert(insertList);
		}
		return num;

	}

	@Override
	public int modifyByMap(DisDesigner oldDisDesigner,
			DisDesigner newDisDesigner) {

		if (!ModelUtils.isModified(oldDisDesigner, newDisDesigner)) {
			return 1;
		}
		Map<String, Object> modifyMap = null;
		try {
			modifyMap = ModelUtils.comparePojo2Map(oldDisDesigner,
					newDisDesigner);
		} catch (Exception e) {
			throw new GlobleException("数据对比失败");
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("desId", oldDisDesigner.getDesId());
			disDesignerDao.updateByMap(modifyMap);
		}
		return 1;
	}

	@Override
	public int modifyByModel(DisDesigner disDesigner) {

		return disDesignerDao.updateByModel(disDesigner);

	}

	@Override
	public int remove(List<Long> list) {

		return disDesignerDao.deleteByIds(list);

	}

	@Override
	public int removeById(Long desId) {

		return disDesignerDao.deleteById(desId);

	}

	@Override
	public int removeByModel(DisDesigner disDesigner) {

		return disDesignerDao.deleteByModel(disDesigner);

	}

	@Override
	public List<DisDesigner> findInPage(DisDesigner disDesigner,
			PaginationVO pageVo) {

		return disDesignerDao.selectInPage(disDesigner, pageVo);

	}

	@Override
	public List<DisDesigner> findByModel(DisDesigner disDesigner) {

		return disDesignerDao.selectByModel(disDesigner);

	}

	@Override
	public int findTotal(DisDesigner disDesigner) {

		return disDesignerDao.selectTotalRecord(disDesigner);

	}

	@Override
	public DisDesigner findById(Long desId) {

		return disDesignerDao.selectById(desId);

	}

	@Override
	public List<DisDesigner> findMySubList(Long desId) {
		
		return disDesignerDao.selectMySubList(desId);
	}
	
}